In [1]:
%load_ext autoreload
%autoreload 2

Historical data¶

Data have been taken from http://www.lazyportfolioetf.com .

Stocks¶

  • Russell 2000 - American Small-Cap market ETF
  • VSS - FTSE All-World ex-US Small-Cap ETF
  • EFA - ex-US Large-Cap market ETF tracking EAFE
  • VTI - CRSP US Total Market Index
  • VNQ - US REIT ETF
  • VUG - CRSP US Large Cap Growth Index ETF
  • GLD - Gold
  • DBC - Commodities

Bonds¶

  • BND - Vanguard Total Bond Market
  • SHY - iShares 1-3 Year Treasury Bond

Analytics¶

In [2]:
from src.statistics import get_max_first_year
from src.data.shares import SHARES_DATA

max_first_year = get_max_first_year(SHARES_DATA.values())
print("max_first_year", max_first_year)
max_first_year 1992

Monthly returns plot¶

In [3]:
import numpy as np
import pandas as pd
import plotly.express as px
from src.statistics import get_max_returns_from_same_year, get_max_first_year, calc_returns_amount_list
from src.plot_utils import get_monthly_data_range
from src.data.shares import SHARES_DATA

max_first_year = get_max_first_year(SHARES_DATA.values())
init_amount = 1000
data = [calc_returns_amount_list(init_amount, x) for x in get_max_returns_from_same_year(SHARES_DATA.values())]

df = pd.DataFrame(
    np.array(data).transpose(),
    columns=list(SHARES_DATA.keys()), 
    index=get_monthly_data_range(max_first_year, 2021)
)

fig = px.line(df, x=df.index, y=df.columns)
fig.show(renderer="notebook+pdf")

Correlations¶

In [4]:
import numpy as np
from src.statistics import get_correlation_table_view, get_stocks_std_view, calc_annual_geometric_mean
from src.data.shares import SHARES_DATA
    
stock_names = list(SHARES_DATA.keys())
corr_table = get_correlation_table_view(SHARES_DATA)

index = stock_names
columns = ["From year", "Mean ret.", "Std", "|", *stock_names]

splitter_column = ["|"] * len(index)
from_column = [x.first_year for x in SHARES_DATA.values()]
annual_mean_column = [f'{round(calc_annual_geometric_mean(x), 2)}%' for x in SHARES_DATA.values()]
std_column = get_stocks_std_view(SHARES_DATA)

df = pd.DataFrame(
    np.array([from_column, annual_mean_column, std_column, splitter_column, *corr_table]).transpose(),
    columns=columns,
    index=index
)
df
Out[4]:
From year Mean ret. Std | VTI EAFE VUG Russell 2000 EAFE Small-Cap VNQ (REIT) GLD DBC BND SHY
VTI 1972 10.98% 15.55% | - 70.62% 96.05% 89.34% 73.6% 61.69% 1.88% 17.08% 16.64% 4.38%
EAFE 1986 7.08% 17.4% | 70.62% - 65.17% 62.51% 85.57% 50.36% 12.83% 32.65% 9.71% -8.3%
VUG 1972 11.1% 16.8% | 96.05% 65.17% - 80.92% 66.28% 52.26% 0.84% 12.25% 17.49% 5.74%
Russell 2000 1985 10.13% 19.74% | 89.34% 62.51% 80.92% - 71.96% 62.29% -3.13% 24.19% 0.76% -19.11%
EAFE Small-Cap 1992 7.95% 16.47% | 73.6% 85.57% 66.28% 71.96% - 57.33% 18.85% 47.89% 5.91% -21.97%
VNQ (REIT) 1972 11.48% 17.09% | 61.69% 50.36% 52.26% 62.29% 57.33% - 5.77% 14.96% 18.19% 3.73%
GLD 1972 7.6% 19.9% | 1.88% 12.83% 0.84% -3.13% 18.85% 5.77% - 27.34% 7.79% 7.08%
DBC 1971 8.21% 18.7% | 17.08% 32.65% 12.25% 24.19% 47.89% 14.96% 27.34% - -3.46% -1.32%
BND 1972 6.72% 5.3% | 16.64% 9.71% 17.49% 0.76% 5.91% 18.19% 7.79% -3.46% - 87.64%
SHY 1977 5.54% 3.03% | 4.38% -8.3% 5.74% -19.11% -21.97% 3.73% 7.08% -1.32% 87.64% -